<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="mini"
      label-width="80px"
    >
      <el-row>
        <el-col :span="6">
          <el-form-item label="项目区域" prop="projectRegion">
            <el-select
              v-model="queryParams.projectRegion"
              placeholder="请选择"
              clearable
              @keyup.enter.native="handleQuery"
            >
              <el-option
                v-for="dict in dict.type.cld_project_region"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="项目名称" prop="projectName">
            <el-input
              v-model="queryParams.projectName"
              placeholder="请输入"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="资产名称" prop="assetsName">
            <el-input
              v-model="queryParams.assetsName"
              placeholder="请输入"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="资产类型" prop="assetsType">
            <el-select
              v-model="queryParams.assetsType"
              placeholder="请选择"
              clearable
              @keyup.enter.native="handleQuery"
            >
              <el-option
                v-for="dict in dict.type.cld_assets_type"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="资产ID" prop="assetsIdCard">
            <el-input
              v-model="queryParams.assetsIdCard"
              placeholder="请输入"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="维修时间">
            <el-date-picker
              v-model="dateRange"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label-width="10px">
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAddOrView"
          v-hasPermi="['cld:repair:add']"
          >新增维修</el-button
        >
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="list" border>
      <el-table-column label="项目区域" align="center" prop="projectRegion">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.cld_project_region"
            :value="scope.row.projectRegion"
          />
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="资产名称" align="center" prop="assetsName" />
      <el-table-column label="资产类型" align="center" prop="assetsType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.cld_assets_type"
            :value="scope.row.assetsType"
          />
        </template>
      </el-table-column>
      <el-table-column label="资产型号" align="center" prop="assetsModel" />
      <el-table-column label="资产ID" align="center" prop="assetsIdCard" />
      <el-table-column label="维修次数" align="center" prop="repairCount" />
      <el-table-column label="维修总成本" align="center" prop="repairMoney">
        <template slot-scope="scope">
          {{
            toMoney(
              (scope.row.fittingMoney ? scope.row.fittingMoney : 0) +
                (scope.row.repairMoney ? scope.row.repairMoney : 0)
            )
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            v-hasPermi="['cld:repair:detailsList']"
            @click="handleRepairDetails(scope.row)"
            >维修明细</el-button
          >
          <el-button
            size="mini"
            type="text"
            v-hasPermi="['cld:repair:cost']"
            @click="handleRepairCost(scope.row)"
            >维修成本</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getRepairList } from "@/api/cld/record";

export default {
  name: "repair",
  dicts: ["cld_assets_type", "cld_project_region"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 资产维修表格数据
      list: [],
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        assetsName: null,
        assetsIdCard: null,
        assetsType: null,
        projectRegion: null,
        projectName: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询资产维修列表 */
    getList() {
      this.loading = true;
      getRepairList(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.list = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 新建 or 查看
    handleAddOrView(row) {
      let assetsRecordId = row.assetsRecordId || 0;
      localStorage.setItem("detailsId", row.assetsDetailsId);
      this.$router.push("/asset/repair/addRepair/" + assetsRecordId);
    },
    /** 维修明细 */
    handleRepairDetails(row) {
      localStorage.setItem("detailsId", row.assetsDetailsId);
      this.$router.push("/asset/repair/details/" + row.assetsDetailsId);
    },
    /** 维修成本 */
    handleRepairCost(row) {
      this.$router.push("/asset/repair-cost/cost/" + row.assetsDetailsId);
    },
  },
};
</script>
<style scoped>
.el-range-editor.el-input__inner {
  width: 100%;
}

.el-select {
  width: 100%;
}
</style>
